home *** CD-ROM | disk | FTP | other *** search
/ APC & TCP 4 / APC & TCP 4.iso / games / publicdomain / a / attacks / sources / history.def < prev    next >
Text File  |  1994-05-14  |  12KB  |  186 lines

  1. DEFINITION MODULE history;
  2.  
  3. (**************************************************************************)
  4. (*                                                                        *)
  5. (*   Here you will find all that you will need to maintain the history    *)
  6. (* list for your Ataxx game program.  Actually, I bet this module would   *)
  7. (* work pretty well for any program where you need a history of the past  *)
  8. (* states.  The available functions for such a history data structure     *)
  9. (* are:                                                                   *)
  10. (*                                                                        *)
  11. (*      InitHistory          Sets up the history data structure so that   *)
  12. (*                           it can then be used.                         *)
  13. (*                                                                        *)
  14. (*      CloseHistory         The logical alternative to InitHistory.      *)
  15. (*                           It needs to be called to clean up properly.  *)
  16. (*                                                                        *)
  17. (*      AddToHistory         This is the constructor.  It's the only way  *)
  18. (*                           to build your history.                       *)
  19. (*                                                                        *)
  20. (*      PopHistory           This removes the last (most recent) item in  *)
  21. (*                           the history data structure and returns it to *)
  22. (*                           the caller.  Its stack-like action gives it  *)
  23. (*                           its name.                                    *)
  24. (*                                                                        *)
  25. (*      ClearHistory         The fast way to get a tabula rasa.           *)
  26. (*                                                                        *)
  27. (**************************************************************************)
  28.  
  29. FROM header
  30.   IMPORT boardtype, histnodeptrtype, historytype, playertype;
  31.  
  32.  
  33.  
  34. PROCEDURE InitHistory (VAR history : historytype;
  35.                        board : boardtype;  player : playertype) : BOOLEAN;
  36.  
  37. (*   This takes an uninitialized variable of history type and sets all    *)
  38. (* the appropriate things to an initial value.                            *)
  39. (*                                                                        *)
  40. (*   INPUT                                                                *)
  41. (*            history           Variable of history type.  It should be   *)
  42. (*                              unused.                                   *)
  43. (*                                                                        *)
  44. (*            board             This board should represent the current   *)
  45. (*                              board state.                              *)
  46. (*                                                                        *)
  47. (*            player            And similarly for the player.             *)
  48. (*                                                                        *)
  49. (*   OUTPUT                                                               *)
  50. (*            history           Same variable.  It will be modified so    *)
  51. (*                              that it will reflect an initial state.    *)
  52. (*                                                                        *)
  53. (*            The function will return TRUE only if it can properly in-   *)
  54. (*            itialize the variable.  If something goes wrong -> FALSE.   *)
  55.  
  56.  
  57. PROCEDURE CloseHistory (VAR history : historytype);
  58.  
  59. (*   This takes a variable of history type and clears all the memory and  *)
  60. (* etc associated with it.                                                *)
  61. (*                                                                        *)
  62. (*   INPUT                                                                *)
  63. (*            history           Variable of history type.                 *)
  64. (*                                                                        *)
  65. (*   OUTPUT                                                               *)
  66. (*            history           Same variable.  It will be modified and   *)
  67. (*                              should NOT be used after calling this     *)
  68. (*                              routine.                                  *)
  69.  
  70.  
  71. PROCEDURE AddToHistory (VAR history : historytype;
  72.                             board : boardtype;  player : playertype)
  73.                               : BOOLEAN;
  74.  
  75. (*   This takes an initialized variable of history type and adds the      *)
  76. (* board to it.  NOTE: it is up to the caller to maintain all the proper  *)
  77. (* changes to its own state.  This just keeps track of the moves.         *)
  78. (*                                                                        *)
  79. (*   INPUT                                                                *)
  80. (*            history           Variable of history type.  It definately  *)
  81. (*                              should be initialized.                    *)
  82. (*                                                                        *)
  83. (*            board             A boardtype.  It is what will be added    *)
  84. (*                              to the history.                           *)
  85. (*                                                                        *)
  86. (*            player            Whose turn it was to move at this board's *)
  87. (*                              configuration.                            *)
  88. (*                                                                        *)
  89. (*   OUTPUT                                                               *)
  90. (*            history           Same variable.  It will be modified so    *)
  91. (*                              that it will now hold the new board.      *)
  92. (*                                                                        *)
  93. (*            The function will return TRUE only if it can properly add   *)
  94. (*            the new board to the history.  If something goes wrong,     *)
  95. (*            then this will try to return the original history and       *)
  96. (*            return FALSE.                                               *)
  97.  
  98.  
  99. PROCEDURE PopHistory (VAR history : historytype;
  100.                      VAR board : boardtype;  VAR player : playertype)
  101.                          : BOOLEAN;
  102.  
  103. (*   This takes an initialized variable of history type and removes the   *)
  104. (* most recent move from it.  The result is put into the variable board.  *)
  105. (* If there are no boards in the current history (ie, the history list    *)
  106. (* is empty) then the function will return FALSE.                         *)
  107. (*                                                                        *)
  108. (*   INPUT                                                                *)
  109. (*            history           Variable of history type.  It definately  *)
  110. (*                              should be initialized.                    *)
  111. (*                                                                        *)
  112. (*            board             A boardtype.  Initially it is garbage.    *)
  113. (*                                                                        *)
  114. (*            player            A playertype.  Also garbage at the start. *)
  115. (*                                                                        *)
  116. (*   OUTPUT                                                               *)
  117. (*            history           Same variable.  It will be modified so    *)
  118. (*                              that it no longer holds the returned      *)
  119. (*                              board.                                    *)
  120. (*                                                                        *)
  121. (*            board             This will hold the board that is re-      *)
  122. (*                              turned.  If the history contains no pre-  *)
  123. (*                              vious boards, then this variable is un-   *)
  124. (*                              changed.                                  *)
  125. (*                                                                        *)
  126. (*            player            Holds